package com.springboot.mybatis.module.admin.index;

import io.swagger.annotations.Api;

import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

















import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springboot.mybatis.common.PageDTO;
import com.springboot.mybatis.common.ResponseDTO;
import com.springboot.mybatis.common.base.back.BaseBackController;
import com.springboot.mybatis.common.redis.RedisUtil;
import com.springboot.mybatis.dao.SysUserMapper;
import com.springboot.mybatis.entity.SysUser;
import com.springboot.mybatis.module.admin.index.dto.ParamDTO;
import com.springboot.mybatis.service.SysUserService;

@Api("首页管理")
@RestController()
@RequestMapping("/admin/index")
public class IndexController extends BaseBackController{
    
    @Resource
    SysUserService sysUserService;
    @Resource
    RedisUtil redisUtil;
    
    
    
    @RequestMapping("/getAll")
    public Object getAll(HttpServletRequest request, @RequestBody ParamDTO user) {
        Page<SysUser> page = PageHelper.startPage(user);
        SysUser sysuser = new SysUser();
        sysuser.setUserName(user.getUserName());
        List<SysUser> list = sysUserService.selectAll(sysuser);
        
        Boolean flag = redisUtil.set("userList", JSONObject.toJSONString(list), 60*10L, TimeUnit.SECONDS);
        if(!flag){
            log.info("wrong");
        }
        Long expire = redisUtil.getExpire("userList", TimeUnit.SECONDS);
        log.info("过期时间: " + expire);
        String str = redisUtil.get("userList");
        if(str == null){
            log.info("wrong");
        }
        List<SysUser> exist = JSONObject.parseObject(str, new TypeReference<List<SysUser>>() {}.getType());
        log.info("list:" + JSONObject.toJSONString(exist));
        PageDTO<SysUser> dto = new PageDTO<SysUser>(page);
        dto.setData(exist);
        return returnJson(new ResponseDTO<SysUser>(dto));
    }
}
